/*
  Simple example for receiving
  
  https://github.com/sui77/rc-switch/
*/

// ********************************************************
// 中断1与中断2无法同时使用切记
// ********************************************************

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

long serialSpeed = 115200;

void setup() {
  Serial.begin(serialSpeed);
  // pinRec315 0: 中断0 NodeMCU -> D3 -> GPIO0
  // arduino nano D2 -> interrept 0
  // arudino nano D3 -> interrept 1
  // 0: rf315, 1:rf433
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}

void loop() {
  if (mySwitch.available()) {
    
    int value = mySwitch.getReceivedValue();
    
    if (value == 0) {
      Serial.print("Unknown encoding");
    } else {
      Serial.print("Received ");
      Serial.print( mySwitch.getReceivedValue() );
      Serial.print(" / ");
      Serial.print( mySwitch.getReceivedBitlength() );
      Serial.print("bit ");
      Serial.print("Protocol: ");
      Serial.println( mySwitch.getReceivedProtocol() );
    }

    mySwitch.resetAvailable();
  }
}
